package com.halflife.framework.generator.template.mapper;

/**
 * Created by zhaoyf on 2018/6/18.
 */
public class UpdateSelectiveAnalysis extends BaseAnalysis {
    public UpdateSelectiveAnalysis(Class clazz) {
        super(clazz);
    }

    @Override
    protected void setPrefix() {
        this.xmlStr.append("<update id=\"updateByPrimaryKeySelective\"  parameterType=\"" + this.clazz.getName() + "\">\n");
        this.xmlStr.append("\t update `" + this.tableName + "` \n");
        this.xmlStr.append("<set>\n");

    }
    protected void comma() {

    }

    @Override
    protected String getValue1(CustomField customField) {
        if (!customField.isPersist()) {
            return  "";
        }
        StringBuilder sb = new StringBuilder();
        sb.append("<if test=\"" + customField.getName() + " != null\">\n");
        sb.append("\t\t").append(customField.getName());
        sb.append(" = #{").append(customField.getName()).append(",jdbcType=").append(customField.getTypeName()).append("},\n");
        sb.append("\t</if>\n");
        return sb.toString();
    }


    ;

    protected void setSuffix() {
        this.xmlStr.append(" \t</set> \n ");
        this.xmlStr.append(" where id = #{id,jdbcType=INTEGER} \n");
        this.xmlStr.append(" </update>");
    }

    ;
}
